package com.hele.sts.action.admin;

import com.hele.sts.dao.QLogDao;
import com.hele.sts.dao.User;
import com.hele.sts.dao.XtLog;
import com.hele.sts.dao.XtLogDao;
import com.hele.sts.webwork.PageAction;
import com.opensymphony.xwork2.ActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class XtLogManagerAction extends PageAction {
    static Logger logger = LoggerFactory.getLogger(XtLogManagerAction.class);

    @Autowired
    private XtLogDao xtLogDao;
    String action;
    String errorInfo;

    String firstFlag;
    String logtype;
    String searchUserid;
    String searchUsername;
    Date startDate;
    Date endDate;
    List<XtLog> logList;

    @Override
    public String execute() throws Exception {
        ActionContext ctx = ActionContext.getContext();
        Map session = ctx.getSession();
        String loginName = (String) session.get("AdminUser.loginName");
        if ((loginName == null) || (loginName.length() < 1)) {
            setErrorInfo("没有登录或登录超时！");
            return "error";
        }
        logger.debug(this.action);
        if(action==null){
            return "list";
        }
        if (("list".equalsIgnoreCase(this.action)) ) {
            return super.execute();
        }
        setErrorInfo("参数错误！");
        return "error";
    }

    @Override
    public String getHref() {
        String href = "";
        return href;
    }

    @Override
    public int count() {
        ActionContext ctx = ActionContext.getContext();
        Map session = ctx.getSession();

        return xtLogDao.count(this.logtype,this.searchUserid,this.startDate,this.endDate);
    }

    @Override
    public String list() {
        ActionContext ctx = ActionContext.getContext();
        Map session = ctx.getSession();
        User adminUser = (User)session.get(("AdminUser"));

        if(firstFlag!=null){
            this.logList = xtLogDao.list(this.logtype,this.searchUsername,this.startDate,this.endDate,getPageNo(), getPageSize());

        }



        return "list";
    }

    public String getErrorInfo() {
        return errorInfo;
    }

    public void setErrorInfo(String errorInfo) {
        this.errorInfo = errorInfo;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public String getFirstFlag() {
        return firstFlag;
    }

    public void setFirstFlag(String firstFlag) {
        this.firstFlag = firstFlag;
    }

    public String getLogtype() {
        return logtype;
    }

    public void setLogtype(String logtype) {
        this.logtype = logtype;
    }

    public String getSearchUserid() {
        return searchUserid;
    }

    public void setSearchUserid(String searchUserid) {
        this.searchUserid = searchUserid;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public String getSearchUsername() {
        return searchUsername;
    }

    public void setSearchUsername(String searchUsername) {
        this.searchUsername = searchUsername;
    }

    public List<XtLog> getLogList() {
        return logList;
    }

    public void setLogList(List<XtLog> logList) {
        this.logList = logList;
    }
}
